package cn.net.yugu.doraemon.api.common.vo;

import cn.net.yugu.doraemon.api.common.model.VO;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

/**
 * @author xiangzr
 * @version 2020/11/12 16:46:33
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class PageQueryVO implements VO {

    private static final long serialVersionUID = -6003189790892237215L;

    private Integer pageNo;
    private Integer pageSize;


    public PageQueryVO setPageNo(Integer pageNo) {
        if (pageNo == null) {
            this.pageNo = 1;
        } else if (pageNo < 1) {
            this.pageNo = 1;
        } else {
            this.pageNo = pageNo;
        }
        return this;
    }

    public PageQueryVO setPageSize(Integer pageSize) {
        if (pageSize == null) {
            this.pageSize = 20;
        } else if (pageSize < 1) {
            this.pageSize = 20;
        } else {
            this.pageSize = pageSize;
        }
        return this;
    }

    public Integer getPageNo() {
        if (pageNo == null) {
            return 1;
        }
        return pageNo;
    }

    public Integer getPageSize() {
        if (pageSize == null) {
            return 20;
        }
        return pageSize;
    }

    public Integer getLimit() {
        return this.getPageSize();
    }

    public Integer getOffset() {
        final int offset = (this.getPageNo() - 1) * this.getLimit();
        return offset;
    }
}
